<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="admin/_fragments :: head(~{::title})">
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>负责人审核</title>

</head>
<style>
    tr td {
        max-width: 200px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
</style>
<body class="user-select">
<section class="container-fluid">
    <header th:replace="admin/_fragments :: header">
    </header>
    <div class="row" th:replace="admin/_fragments :: menu(2)">
    </div>
</section>

<div class="col-sm-9 col-sm-offset-3 col-md-10 col-lg-10 col-md-offset-2 main" id="main">
    <form action="#" method="post">
        <h1 class="page-header">管理 <span class="badge" th:text="${Quantity.n_lead_num}">7</span></h1>
        <div class="table-responsive">
            <table class="table table-striped table-hover">
                <thead>
                <tr>
                    <th><span class="glyphicon glyphicon-th-large"></span> <span class="visible-lg">选择</span></th>
                    <th><span class="glyphicon glyphicon-lock"></span> <span class="visible-lg">ID</span></th>
                    <th><span class="glyphicon glyphicon-file"></span> <span class="visible-lg">姓名</span></th>
                    <th><span class="glyphicon glyphicon-list"></span> <span class="visible-lg">性别</span></th>
                    <th class="hidden-sm"><span class="glyphicon glyphicon-tag"></span> <span
                            class="visible-lg">年龄</span></th>
                    <th class="hidden-sm"><span class="glyphicon glyphicon-globe"></span> <span
                            class="visible-lg">地址</span></th>
                    <th><span class="glyphicon glyphicon-comment"></span> <span class="visible-lg">理由</span></th>
                    <th><span class="glyphicon glyphicon-play"></span> <span class="visible-lg">计划</span></th>
                    <th><span class="glyphicon glyphicon-pencil"></span> <span class="visible-lg">操作</span></th>
                </tr>
                </thead>
                <tbody class="table-striped" th:each="lead : ${page.content}">
                <tr>
                    <td><input type="checkbox" class="input-control" name="checkbox[]" value=""/></td>
                    <td onclick="detail(this.id)" th:id="${lead.id}" class="hidden-sm" id="lead_id" th:text="${lead.id}">1</a></td>
                    <td onclick="detail(this.id)" th:id="${lead.id}" class="hidden-sm" th:text="${lead.name}">猪猪</a></td>
                    <td onclick="detail(this.id)" th:id="${lead.id}" th:text="${lead.sex} eq '0'?'男':'女'">男</td>
                    <td onclick="detail(this.id)" th:id="${lead.id}" class="hidden-sm" th:text="${lead.age}">18</td>
                    <td onclick="detail(this.id)" th:id="${lead.id}" class="hidden-sm" th:text="${lead.location}">珠海</td>
                    <td onclick="detail(this.id)" th:id="${lead.id}" th:text="${lead.reason}">会更好</td>
                    <td onclick="detail(this.id)" th:id="${lead.id}" th:text="${lead.plan}">我计划这样做</td>
                    <td><a href="#" id="agree">同意</a><a href="#" rel="6" id="refuse"> 拒绝</a></td>
                </tr>
                </tbody>
            </table>
        </div>
        <footer class="message_footer">
            <nav>
                <div class="btn-toolbar operation" role="toolbar">
                    <div class="btn-group" role="group"><a class="btn btn-default" onClick="select()">全选</a> <a
                            class="btn btn-default" onClick="reverse()">反选</a> <a class="btn btn-default"
                                                                                  onClick="noselect()">不选</a></div>
                    <div class="btn-group" role="group">
                        <button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="bottom"
                                title="拒绝全部选中" name="checkbox_delete" id="checkbox_refuse">拒绝
                        </button>
                        <button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="bottom"
                                title="同意全部选中" name="checkbox_agree" id="checkbox_agree">同意
                        </button>
                    </div>
                </div>
                <div th:if="${page.totalPages}>1">
                    <div class="ui middle aligned grid" style="width: 250px;float: right;">
                        <div class="column" style="width: 100px">
                            <a href="#" th:href="@{/admin/admin_lead/(page=${page.number}-1)}" th:unless="${page.first}"
                               class="ui mini teal basic button">上一页</a>
                        </div>
                        <div class="right aligned column" style="width: 100px;">
                            <a href="#" th:href="@{/admin/admin_lead/(page=${page.number}+1)}" th:unless="${page.last}"
                               class="ui mini teal basic button">下一页</a>
                        </div>
                    </div>
                </div>
            </nav>
        </footer>
    </form>
</div>


<script src="../../static/js/jquery.js" type="text/javascript" th:src="@{/js/jquery.js}"></script>
<script src="../../static/js/admin-scripts.js" type="text/javascript" th:src="@{/js/admin-scripts.js}"></script>
<script src="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.js"></script>
<script src="../../js/bootstrap.min.js" th:src="@{/js/bootstrap.min.js}"></script>
<script>
    //审核同意
    $(document).on("click", "#agree", function () {
        var ids = $(this).parents("tr").find("td:eq(1)").text();
        $.ajax({
            url: "/admin/agree/" + ids,
            async: false,
            type: "POST",
            success: function (result) {
                if (result.code === 200) {
                    window.location.href = "/admin/admin_lead";
                } else {
                    alert("错误，请联系管理员");
                }
            }
        });
    });

    //审核不同意
    $(document).on("click", "#refuse", function () {
        var ids = $(this).parents("tr").find("td:eq(1)").text();
        $.ajax({
            url: "/admin/refuse/" + ids,
            async: false,
            type: "POST",
            success: function (result) {
                if (result.code === 200) {
                    window.location.href = "/admin/admin_lead";
                } else {
                    alert("错误，请联系管理员");
                }
            }
        });
    });

    function detail(id) {
        window.location.href = "/admin/lead/" + id;
    }

    //点击全部同意，批量添加
    $(document).on("click", "#checkbox_agree", function () {
        alert("111");
        var ids = "";
        $.each($(".input-control:checked"), function () {
            //组装员工id字符串
            ids += $(this).parents("tr").find("td:eq(1)").text() + "-";
        });
        if (ids === "") {
            alert("请选择");
        } else {
            ids = ids.substring(0, ids.length - 1);
            $.ajax({
                url: "/admin/agree/" + ids,
                async: false,
                type: "POST",
                success: function (result) {
                    if (result.code === 200) {
                        window.location.href = "/admin/admin_lead";
                    } else {
                        alert("错误，请联系管理员");
                    }
                }
            });
        }
    });

    //点击全部拒绝，批量拒绝
    $(document).on("click", "#checkbox_refuse", function () {
        var ids = "";
        $.each($(".input-control:checked"), function () {
            //组装员工id字符串
            ids += $(this).parents("tr").find("td:eq(1)").text() + "-";
        });
        if (ids === "") {
            alert("请选择");
        } else {
            ids = ids.substring(0, ids.length - 1);
            $.ajax({
                url: "/admin/refuse/" + ids,
                async: false,
                type: "POST",
                success: function (result) {
                    if (result.code === 200) {
                        window.location.href = "/admin/admin_lead";
                    } else {
                        alert("错误，请联系管理员");
                    }
                }
            });
        }
    });
</script>
</body>
</html>
